package demo1;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2023-12-04
 * Time: 14:02
 */

/*给你一个字符串 s ，将该字符串中的大写字母转换成相同的小写字母，返回新的字符串。

        示例 1：

        输入：s = "Hello"

        输出："hello"



        示例 2：

        输入：s = "here"

        输出："here"



        示例 3：

        输入：s = "LOVELY"

        输出："lovely"*/

public class Test {

    public static void main(String[] args) {

    }

    public static boolean isPalindrome(String s) {
        s = s.toLowerCase();
        int left = 0;
        int right = s.length() - 1;
        while(left < right) {
            while(left < right && !isVaildChar(s.charAt(left))) {
                left++;
            }
            while(left < right && !isVaildChar(s.charAt(right))) {
                right--;
            }
            if(s.charAt(left) != s.charAt(right)) {
                return false;
            }else {
                left++;
                right--;
            }

        }
        return false;
    }

    private static boolean isVaildChar(char ch) {
        if(Character.isDigit(ch) || Character.isLetter(ch)) {
            return true;
        }
        return false;
    }

    public static void main6(String[] args) {
        System.out.println(isPalindrome("aaabbbcccc"));
    }

    public static void main4(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            int index = str.lastIndexOf(' ');
            String tmp = str.substring(index+1);
            System.out.println(tmp.length());
        }
    }

    public static void main5(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            int index = str.lastIndexOf(' ');
            String tmp = str.substring(index+1);
            System.out.println(tmp.length());
        }
    }

    public static void main3(String[] args) {
        String s = "Hello e   e    eee     a";
        String[] ret = s.split(" ");
        for (String strings:ret) {
            System.out.println(strings);
        }
        //System.out.println(Arrays.toString(ret));
        /*System.out.println(s.isEmpty());
        System.out.println(s.length());
        System.out.println(s.trim());*/
    }



    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        System.out.println(s.toLowerCase());
    }

    public static void main1(String[] args) {
        String s = "Hello, my name is John";
        int count = 0;
        int i = 0;
        String[] ret = s.split(" ");
        for (; i < ret.length; i++) {
            System.out.println(ret[i]);
        }
        count = i;
        System.out.println(count);
    }
}
